<?php get_header();
?>
<div id="container">	
    <div class="wrapper">
    	<div class="grid24" style="margin-top:20px;">
        	<?php get_sidebar(); ?>
            <div class="grid18"><!-- content -->
            	<div class="crumbs">
                	<?php qt_custom_breadcrumbs(0, 1); ?>
                </div> 
                <?php if( have_posts() ) : the_post(); ?>
                <?php 
				//$customInfo = get_post_meta( $post->ID, '_mb_attribute', true );
				$country	= get_countries(get_bloginfo('template_url').'/data/countries.xml');
				$knowUs		= get_dataXML(get_bloginfo('template_url').'/data/knowUs.xml', 'through');
				$typeTravel	= get_dataXML(get_bloginfo('template_url').'/data/typeTravel.xml', 'type');
				$paymentMe	= get_dataXML(get_bloginfo('template_url').'/data/paymentMethod.xml', 'through');
				$tab_info		= get_post_meta( $post->ID, '_mb_tab_info', true );
                $totalTab		= count($tab_info);
				//$gender_arr = array('Mr', 'Ms', 'Mrs');
				$class_arr	= array(1 => 'Luxury Cruises', 2 => 'Superior Cruises', 3 => 'Deluxe Cruise'); 
				$cabin_arr	= array(1 => '1 Cabin', 2 => '2 Cabins', 3 => '3 Cabins', 4 => '4 Cabins', 5 => '5 Cabins', 6 => '6 Cabins', 7 => '7 Cabins', 8 => '8 Cabins', 9 => '9 Cabins', 10 => '10 Cabins');  
				//$cruise_arr	= array(1 => 'Cruise 1 day', 2 => 'Cruise 2 day', 3 => 'Cruise 3 day');
				$url = get_permalink();
				$checkin	= trim($_POST['checkin']);
				$packageID	= intval($_POST['package']);
				$isSentMail = 0;
				//echo $tab_info[$packageID]['title'];
				//echo '<a href="'. get_permalink() .'">'. get_the_title() .'</a>';
				if( isset($_POST['btnSubmit']) ) {
					remove_wp_magic_quotes();
					$data = array(
						'subject'			=> 'Contact of '. trim($_POST['yname']),
						'msg_title'			=> 'Contact from VietnamHalongCruises.com',
						//'to_email'		=> get_option('admin_email'),
						'to_email'			=> 'lehoang.tnk@gmail.com',
						//'cc'				=> 'lehoang.tnk@gmail.com',
						//'bcc'			=> get_option('admin_email'),
						//'sex'			=> $gender_arr[$_POST['sex']],
						
						'from_name'			=> trim($_POST['yname']), 
						'from_email'		=> trim($_POST['yemail']),
						//'confirm_email'		=> trim($_POST['cfemail']),
						'alter_email'		=> trim($_POST['alternate_email']),
						'phone_number'		=> trim($_POST['phone_number']),
						'national'			=> trim($_POST['national']),
						
						'checkin'			=> trim($_POST['checkin']),
						'of_cruise'			=> trim($_POST['cruiser']),
						'numAdult'			=> $_POST['numAdult'],
						'overAdult'			=> trim($_POST['overAdult']), 
						'numCabin'			=> $cabin_arr[$_POST['numCabin']],
						//'overCabin'			=> trim($_POST['overCabin']), 
						'room_type'			=> $class_arr[$_POST['roomtype']],
						'children'			=> trim($_POST['children']),
						'Single'			=> $_POST['Single'],
						'OverRoom1'			=> trim($_POST['OverRoom1']), 
						'Double'			=> $_POST['Double'],
						'OverRoom2'			=> trim($_POST['OverRoom2']),
						'request'		 	=> trim($_POST['request']),
							
						'prefered_payment'	=> trim($_POST['prefered']),
						'type_travel'		=> trim($_POST['travel']),
						'you_know'			=> trim($_POST['yknow'])
									
					);
					if( wp_booking_cruise($data) ) {
						$isSentMail = 1;
					}
				} 
				if( $isSentMail ) { ?>
					<div class="mail-sent-ok" style="display: block;">
						  <p>Your message has been sent.<br />As soon as we receive your request, we will confirm immediately.<br />Thank you!</p>
							<p><a href="<?php echo HOME_URL; ?>" style="text-decoration:underline">Click here</a> to return home page</p>
					</div>
					<?php
				} else { ?>
                    <div class="white_frame">
                        <div class="text">
                            <h1><?php the_title(); ?></h1>
                            <?php 
                            $thuoctinh_arr	= get_post_meta( $post->ID, '_mb_attribute', true );
                            
                            echo $thuoctinh_arr["tomtat"]; 
                            
                            $tab1 = 'active';
                            $tab_booking = '';
                            $tab_content1 = 'block';
                            $tab_content_booking = 'none';
                            $isSearch = $_POST['isSearch'];
                            if( $isSearch ) {
                                $tab1 = '';
                                $tab_booking = 'active';
                                $tab_content1 = 'none';
                                $tab_content_booking = 'block';
                            }
                            $isPrice = $wpdb->get_col("SELECT count(*) AS total FROM {$table_prefix}price_season WHERE post_id=". $post->ID);
                            ?>
                        </div>      	
                        <figure class="featured-thumbnail_large">
                            <?php echo get_the_post_thumbnail($post->ID); ?>
                        </figure>
                        <div id="tabs_wrapper">
                            <div id="tabs_container">
                                <ul id="tabs">
                                    <li style="margin-right:0" class="<?php echo $tab1; ?>"><a href="#tab_1"><?php echo ( ($totalTab) ? 'Overview' : 'Itinerary' ); ?></a></li>
                                    <!--li class=""><a href="#tab_2" class="icon_noprice">Itinerary</a></li-->
                                    <?php 
                                    $optPackage = '';
                                    $j = $k = 1;
                                    if( $totalTab ) {
                                        for( $i = 0; $i < $totalTab; $i = $i + 2 ) {
                                            ++ $j;
                                            $optPackage .= '<option value="'. $i .'"'. ( ($packageID == $i) ? ' selected="selected"' : '') .'>'. $tab_info[$i]['title'] .'</option>';
                                            ?><li class=""><a href="#tab_<?php echo $j; ?>" class="icon_noprice"><?php echo $tab_info[$i]['title']; ?></a></li><?php
                                        } 
                                    } ?>
                                    <li class="<?php echo $tab_booking; ?>"><a href="#tab_<?php echo ++ $j; ?>" class="icon_noprice">Price &amp; booking</a></li>
                                </ul>
                            </div><!-- tabs container -->
                            <div id="tabs_content_container">                	
                                <div class="tab_content" id="tab_1" style="display: <?php echo $tab_content1; ?>;">
                                    <div class="content_tab"><!-- content -->
                                        <?php the_content(); ?>
                                    </div><!-- content -->  
                                </div><!-- tab 1 -->
                                <?php 
                                if( $totalTab ) {
                                    $k = 1;
                                    for( $i = 0; $i < $totalTab; $i = $i + 2 ) {
                                        ++ $k;
                                        ?>  
                                        <div class="tab_content" id="tab_<?php echo $k; ?>" style="display: none;">        									
                                            <div class="content_tab">
                                            <?php echo $tab_info[$i+1]['detail']; ?>
                                            </div>
                                        </div>
                                        <?php
                                    } 
                                } ?>
                                <div class="tab_content" id="tab_<?php echo ++ $k; ?>" style="display: <?php echo $tab_content_booking; ?>;"><!-- tab 3 -->
                                    <div class="content_tab"><!-- content -->
                                        <?php
                                        $price_info	= get_post_meta( $post->ID, '_mb_attribute', true );
                                        echo $price_info["price_info"];
                                        if( $isPrice[0] ) 
                                        {
                                            $sql_Group = $wpdb->get_results("SELECT DISTINCT g.group_id, group_name 
                                                FROM {$table_prefix}price_season s, {$table_prefix}price_class c, {$table_prefix}price p, {$table_prefix}price_group g
                                                WHERE s.season_id=c.season_id AND c.class_id=p.class_id AND p.group_id=g.group_id AND s.post_id=". $post->ID ." ORDER BY price_public DESC;");
                                            
                                            $sql_Season = $wpdb->get_results("SELECT * FROM {$table_prefix}price_season WHERE post_id=". $post->ID ." ORDER BY season_order ASC;");
                                            foreach ( $sql_Season as $sqlSeason ) 
                                            {
                                                echo '<h3 class="titleSeason">'. $sqlSeason->season_name .'</h3>';
                                                echo $sqlSeason->season_info;
                                                
                                                $sql_Class = $wpdb->get_results("SELECT * FROM {$table_prefix}price_class WHERE season_id=". $sqlSeason->season_id ." AND class_status=1 ORDER BY class_order ASC;");
                                                if( $sql_Class ) 
                                                {
                                                    ?><table class="tblSeason">
                                                    <tr><th rowspan="2">Grade tour</th>
                                                        <th colspan="<?php echo count($sql_Group); ?>">Price per person in US$</th>
                                                        <th rowspan="2">Single<br />supplement</th></tr>
                                                    <tr><?php
                                                    foreach ( $sql_Group as $sqlGroup ) {
                                                        echo '<th>'. $sqlGroup->group_name .'</th>';
                                                    }
                                                    echo '</tr>';
                                                    foreach( $sql_Class as $sqlClass ) {
                                                        $sql_Price = $wpdb->get_results("SELECT * FROM {$table_prefix}price WHERE class_id=". $sqlClass->class_id ." ORDER BY price_public DESC;");
                                                        ?><tr><td class="className"><?php echo $sqlClass->class_name; ?></td><?php 
                                                        $priceGroup = array();
                                                        foreach( $sql_Price as $sqlPrice ) {
                                                            $priceGroup[$sqlPrice->group_id] = $sqlPrice->price_public;
                                                        } 
                                                        foreach ( $sql_Group as $sqlGroup ) {
                                                            echo '<td>$ '. $priceGroup[$sqlGroup->group_id] .'</td>';
                                                        }
                                                        echo '<td>$ '. $sqlClass->class_extra .'</td>';
                                                        echo '</tr>';
                                                    }
                                                    echo '</table>
                                                    <div style="text-align: center; color: rgb(184, 1, 1); font-size: 11px; margin-bottom: 20px;">(Seasonal prices apply and will be confirmed when booking! All rates are quoted in US$/person)</div>';
                                                }
                                            }
                                        }// 
                                        echo $customType['price_info'];
                                        echo '</div><!--end .blockPrice-->';
                                        ?>
                                        <!--code scrip calendar:-->          
                                        <link rel="stylesheet" type="text/css" href="<?php echo TEMPLATE_URL; ?>/src/css/jscal2.css" />
                                        <link rel="stylesheet" type="text/css" href="<?php echo TEMPLATE_URL; ?>/src/css/border-radius.css" />
                                        <link rel="stylesheet" type="text/css" href="<?php echo TEMPLATE_URL; ?>/src/css/gold/gold.css" />
                                        <script src="<?php echo TEMPLATE_URL; ?>/src/js/jscal2.js"></script>
                                        <script src="<?php echo TEMPLATE_URL; ?>/src/js/lang/en.js"></script>
                                        <!--end code scrip calendar:-->
                                        <script type="text/javascript">     
                                        function OverNumber( me, default_me, num, over_num )
                                        {
                                            if( me > default_me ) {
                                                document.getElementById(over_num).value = me;
                                                document.getElementById(num).style.display = 'none';
                                                document.getElementById(over_num).style.display = '';
                                                document.getElementById(over_num).select();
                                            } else {
                                                document.getElementById(num).selectedIndex = me;
                                                document.getElementById(num).style.display = '';
                                                document.getElementById(over_num).style.display = 'none';
                                            }
                                        }
                                        </script>
                                        <h4 class="title_heading">Cruise Booking Form</h4>
                                        <div class="note1"><span>*</span> <b>indicates a required field</b>&nbsp;&nbsp;</div>
                                        <div class="booking_form">
                                            <form class="frmbooking" method="post" action="<?php echo $url; ?>">
                                                <h5>Contact information</h5>
                                                <div>
                                                    <label>Full name:</label>
                                                    <input type="text" required value="<?php echo $data['from_name']; ?>" name="yname">
                                                    <span class="indicates">*</span>
                                                </div>
                                                <div>
                                                    <label>Email:</label>
                                                    <input type="text" name="yemail" value="<?php echo $data['from_email']; ?>" required>
                                                    <span class="indicates">*</span>
                                                </div>
                                                <div>
                                                    <label>Confirm Email:</label>
                                                    <input type="text" required value="<?php echo $data['confirm_email']; ?>" name="cfemail"> <span class="indicates">*</span>
                                                </div>
                                                <div>
                                                    <label>Alternate Email:</label>
                                                    <input type="text" value="<?php echo $data['alter_email']; ?>" name="alternate_email">
                                                </div>
                                                <div>
                                                    <label>Phone number:</label>
                                                    <input type="text" value="<?php echo $data['phone_number']; ?>" name="phone_number">
                                                </div>
                                                <div>
                                                    <label>Nationality:</label>
                                                    <select style="width:289px" required="" name="national">
                                                        <option value="" selected="">Select nationality</option>
                                                          <?php foreach ($country as $key => $value) : ?>
                                                          <option value="<?php echo $key; ?>" <?php if( $data['national'] == $key ) echo 'selected="selected"' ?>><?php echo $key; ?></option>
                                                          <?php endforeach; ?>                                        
                                                     </select>
                                                     <span class="indicates">*</span>
                                                </div>
                                                <h5>Intinerary information</h5>
                                                <div>
                                                    <label>Expected departure date:</label>
                                                    <span id="trigger-departure">
                                                        <input type="text" required value="<?php echo ((!empty($checkin)) ? $checkin : ''); ?>" name="checkin" id="departure">
                                                        </span>
                                                        <script type="text/javascript">
                                                            Calendar.setup({ dateFormat: "%b %d, %Y", trigger: "trigger-departure", inputField: "departure",
                                                            min: <?php echo date("Ymd"); ?>, onSelect:function() { this.hide(); }});
                                                        </script>
                                                        <span class="indicates">*</span>
                                                    </span>                                           
                                                </div>
                                                <div><label>Length of cruise:</label>
                                                    <select name="package">
                                                    <?php 
                                                    if( $totalTab > 1 ) {
                                                        echo $optPackage;
                                                    } else {
                                                        echo '<option value=0>Only one cruise package</option>';
                                                    } ?>
                                                    </select>
                                                    <span class="indicates">*</span>
                                                </div>
                                                <div>
                                                    <label>No.of adult:</label>
                                                    <?php if( $data['overAdult'] > 10 ) {
                                                        $DisplayAdult1 = 'none';
                                                        $DisplayAdult2 = 'inline';
                                                    } else {
                                                        $DisplayAdult1 = 'inline';
                                                        $DisplayAdult2 = 'none';
                                                    }?>
                                                    <select name="numAdult" id="numAdult" style="display: <?php echo $DisplayAdult1; ?>" onchange="OverNumber(this.value, 10, 'numAdult', 'overAdult');">
                                                        <?php for( $i=0; $i<=10; $i++ ) : ?>
                                                        <option value="<?php echo $i; ?>"<?php if( $data['overAdult'] == $i ) : echo ' selected="selected"'; endif; ?>><?php echo $i; ?></option>
                                                        <?php endfor; ?>
                                                        <option value="11">Over</option>
                                                    </select>
                                                    <input name="overAdult" id="overAdult" value="<?php echo intval($data['number_adult']); ?>" type="text" maxlength="3" style="display: <?php echo $DisplayAdult2; ?>" onchange="OverNumber(this.value, 10, 'numAdult', 'overAdult');" />
                                                    <span class="indicates">*</span>
                                                </div>
                                                <div>
                                                    <label>No.of cabin:</label>
                                                    <select name="numCabin">
                                                        <?php foreach ($cabin_arr as $key => $value) : ?>
                                                        <option value="<?php echo $key; ?>"<?php if( $_POST['numCabin'] == $key ) : echo ' selected="selected"'; endif; ?>><?php echo $value; ?></option>
                                                        <?php endforeach; ?>                                                    
                                                    </select>                                           
                                                    <span class="indicates">*</span>
                                                </div>
                                                <div><label>Cabin class:</label>
                                                    <select name="roomtype">
                                                        <?php foreach ($class_arr as $key => $value) : ?>
                                                        <option value="<?php echo $key; ?>"<?php if( $_POST['room_type'] == $key ) : echo ' selected="selected"'; endif; ?>><?php echo $value; ?></option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                    <span class="indicates">*</span>
                                                </div>
                                                <div>
                                                    <label>Name  &amp; age of children:</label>
                                                    <textarea required"<?php echo $data['children']; ?>" name="children" cols="1" rows="5"></textarea>
                                                </div>
                                                <div>
                                                    <label>Room Preference:</label>
                                                    <?php if( $data['OverRoom1'] > 10 ) {
                                                        $DisplayRoom1 = 'none';
                                                        $DisplayRoom_1 = 'inline';
                                                    } else {
                                                        $DisplayRoom1 = 'inline';
                                                        $DisplayRoom_1 = 'none';
                                                    }?>
                                                    <span>Single</span>
                                                    <select name="Single" id="Single" class="inForm book_input" style="width:65px; display: <?php echo $DisplayRoom1; ?>" onchange="OverNumber(this.value, 10, 'Single', 'OverRoom1');">
                                                        <?php for( $i=0; $i<=10; $i++ ) : ?>
                                                        <option value="<?php echo $i; ?>"<?php if( $data['Single'] == $i ) : echo ' selected="selected"'; endif; ?>><?php echo $i; ?></option>
                                                        <?php endfor; ?>
                                                        <option value="11">Over</option>
                                                    </select>
                                                    <input type="text" onchange="OverNumber(this.value, 10, 'Single', 'OverRoom1');" style="width:20px; height:10px; display: <?php echo $DisplayRoom_1; ?>" maxlength="3" class="text book_input" value="<?php echo $data['OverRoom1']; ?>" id="OverRoom1" name="OverRoom1">
                                                    <?php if( $data['OverRoom2'] > 10 ) {
                                                        $DisplayRoom2 = 'none';
                                                        $DisplayRoom_2 = 'inline';
                                                    } else {
                                                        $DisplayRoom2 = 'inline';
                                                        $DisplayRoom_2 = 'none';
                                                    }?>
                                                    <span>Double</span>
                                                    <select name="Double" id="Double" class="inForm book_input" style="width:65px; display: <?php echo $DisplayRoom2; ?>" onchange="OverNumber(this.value, 10, 'Double', 'OverRoom2');">
                                                        <?php for( $i=0; $i<=10; $i++ ) : ?>
                                                        <option value="<?php echo $i; ?>"<?php if( $data['Double'] == $i ) : echo ' selected="selected"'; endif; ?>><?php echo $i; ?></option>
                                                        <?php endfor; ?>
                                                        <option value="11">Over</option>
                                                    </select>
                                                    <input type="text" onchange="OverNumber(this.value, 10, 'Double', 'OverRoom2');" style="width:20px; height:10px; display: <?php echo $DisplayRoom_2; ?>" maxlength="3" class="text book_input" value="<?php echo $data['OverRoom2']; ?>" id="OverRoom2" name="OverRoom2">
                                                </div>
                                                <div>
                                                    <label>Special request:</label>
                                                    <textarea required"<?php echo $data['special_request']; ?>" name="request" cols="1" rows="10"></textarea>
                                                    <span class="indicates">*</span>
                                                </div>
                                                
                                                <h5>Additional Information</h5>
                                                     <div>
                                                     <label>Prefered Payment method:</label>
                                                     <select style="width:291px" required="" name="prefered">
                                                          <option value="" selected=""></option>
                                                          <?php foreach ($paymentMe as $key => $value) : ?>
                                                          <option value="<?php echo $key; ?>" <?php if( $data['prefered_payment'] == $key ) echo 'selected="selected"' ?>><?php echo $key; ?></option>
                                                          <?php endforeach; ?>
                                                     </select>
                                                </div>
                                                <div>
                                                    <label>Type of travel:</label>
                                                    <select style="width:291px" required="" name="travel">
                                                          <option value="" selected=""></option>
                                                          <?php foreach ($typeTravel as $key => $value) : ?>
                                                          <option value="<?php echo $key; ?>" <?php if( $data['type_travel'] == $key ) echo 'selected="selected"' ?>><?php echo $key; ?></option>
                                                          <?php endforeach; ?>
                                                    </select>
                                                </div>
                                                <div>
                                                    <label>You know us throught:</label>
                                                    <select style="width:291px" required="" name="yknow">
                                                          <option value="" selected=""></option>
                                                          <?php foreach ($knowUs as $key => $value) : ?>
                                                          <option value="<?php echo $key; ?>" <?php if( $data['you_know'] == $key ) echo 'selected="selected"' ?>><?php echo $key; ?></option>
                                                          <?php endforeach; ?>
                                                    </select>
                                                </div>
                                                <div class="frmbooking_divbtn">
                                                    <input type="reset" value="clear">
                                                    <input type="submit" class="" value="send" name="btnSubmit">               
                                                </div>                                        
                                            </form>
                                        </div><!-- booking form -->
                                    </div><!-- content_tab -->           
                                </div><!-- end tab_content -->                
                            </div><!-- end tab content container -->
                       </div><!-- tabs_wrapper -->
                    <?php 
                    } ?>
                    	<div class="white_frame">
                            <div class="text">
                            <h1>other tour</h1>
                            <?php 
							//ECHO $post->ID;
							//print_r($post);
							$taxonomy = 'cruise_category';
							$terms = wp_get_post_terms( $post->ID, $taxonomy );
                            $mysql = $wpdb->get_results("SELECT p.ID, post_title, post_name
                                FROM $wpdb->posts p 
                                INNER JOIN $wpdb->term_relationships tr ON(p.ID = tr.object_id) 
                                INNER JOIN $wpdb->term_taxonomy tt ON(tr.term_taxonomy_id = tt.term_taxonomy_id)  
                                WHERE tt.term_id=". $terms[0]->term_id ." AND tt.taxonomy='{$taxonomy}' AND post_type='cruise' AND post_status='publish' AND post_parent=0 ORDER BY post_date DESC;");
                            foreach ( $mysql as $post ) { 
                                ?>
                                   <!--article class="recommend">
                                       <!--figure class="featured-thumbnail">
                                             <a href="<?php /*?><?php the_permalink(); ?>">
                                                    <?php 
                                                        if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
                                                          the_post_thumbnail('thumbnail');
                                                        } 
                                                     ?><?php */?>
                                             </a>                                   
                                        </figure-->
                                        <div class="box_body_1">
                                        	<ul class="reason">
                                            <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
                                            <!--p>
                                            <?php /*?><?php 
                                                $thuoctinh_arr = get_post_meta( $post->ID, '_mb_attribute', true );
                                                echo $thuoctinh_arr["tomtat"];
                                                //echo GetWords($thuoctinh_arr["tomtat"], 350);
                                            ?><?php */?>
                                            </p-->  
                                            </ul>                          
                                        </div>
                                   <!--/article-->
                                <?php
                            }
                            ?>
                            </div>
                        </div><!-- end white_frame -->
                    </div><!-- end white frame -->
            </div><!-- grid18 -->
          <?php endif ?>
        </div><!-- grid24 -->
    </div><!-- wrapper -->
</div> <!-- container -->
<?php get_footer(); ?>